﻿namespace KinonekoSoftware.Studio.Utils
{
    public class KeywordCatalogFlattenDictionary : FlattenDictionary<string, KeywordCatalog>
    {

        public KeywordCatalogFlattenDictionary() : base(GetID, GetParentID, HasParent, IsRoot, BuildParent)
        {
        }

        private static string GetID(KeywordCatalog catalog) => catalog.Id;
        private static string GetParentID(KeywordCatalog catalog) => catalog.ParentID;
        private static bool HasParent(KeywordCatalog catalog) => !string.IsNullOrEmpty(catalog.ParentID);
        private static bool IsRoot(KeywordCatalog catalog) => string.IsNullOrEmpty(catalog.ParentID);
        private static void BuildParent(KeywordCatalog parent, KeywordCatalog child)
        {
            parent.Children.Add(child);
        }
    }
}